from django.contrib import admin
from apps.files.models import File
from django.utils.translation import ugettext_lazy as _, ungettext
from apps.files import get_model

class FilesAdmin(admin.ModelAdmin):
    fieldsets = (
        (None,
           {'fields': ('content_type', 'object_pk')}
        ),
        (_('Content'),
           {'fields': ('user', 'file', 'filename', 'file_title', 'file_description')}
        ),
        (_('Metadata'),
           {'fields': ('submit_date', 'ip_address', 'is_public', 'is_removed')}
        ),
     )

    list_display = ('file_title', 'content_type', 'filename', 'ip_address', 'submit_date', 'is_public', 'is_removed')
    list_display_links = ('file_title','filename')
    list_filter = ('submit_date', 'is_public', 'is_removed')
    date_hierarchy = 'submit_date'
    ordering = ('-submit_date',)
    raw_id_fields = ('user',)
    search_fields = ('file', 'user__username', 'user_name', 'ip_address')

    
# Only register the default admin if the model is the built-in file model
# (this won't be true if there's a custom file app).
if get_model() is File:
    admin.site.register(File, FilesAdmin)
    from django.contrib.contenttypes.models import ContentType
    admin.site.register(ContentType)
